<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户列表</title>
</head>
<body>
<c:choose>
    <c:when test="${empty sessionScope.user}">
        <%
            request.setAttribute("msg", "您还没有登录");
            request.getRequestDispatcher("./login.jsp").forward(request, response);
        %>
    </c:when>
    <c:otherwise>
        <%--    已经处于登录状态    --%>
        当前用户名：${sessionScope.user.username}
        <a href="./user.do?action=quit">退出</a>
        <table border="1px" width="50%" align="center">
            <tr>
                <th>用户名</th>
                <th>IP地址</th>
                <th>登录时间</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${applicationScope.onlineUsers}" var="entry">
                <tr>
                    <td>${entry.value.username}</td>
                    <td>${entry.value.ip}</td>
                    <td>${entry.value.loginTime}</td>
                    <td><a href="./user.do?action=kick&username=${entry.value.username}">踢他</a></td>
                </tr>
            </c:forEach>
        </table>
    </c:otherwise>
</c:choose>
</body>
</html>
